package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.Order;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface ReportMapper extends BaseMapper {

    @Select("SELECT COUNT(o.SETMEAL_ID) AS count,s.name, s.remark\n" +
            "FROM setmeal_t s , order_t o \n" +
            "WHERE s.ID = o.SETMEAL_ID\n" +
            "group by s.id \n" +
            "order by count desc")
    List<Map<String, Object>> findSetmealProportion();
    //会员

    @Select("SELECT count(*) FROM member_t where date_format(create_date,'%Y-%m') = date_format(curdate() , '%Y-%m')")
    Integer findMemberByMonth();
    @Select("SELECT count(*) FROM  member_t WHERE YEARWEEK(create_date) = YEARWEEK(now())")
    Integer findMemberByWeek();
    @Select("select count(name) from member_t")
    Integer findMemberCount();
    @Select("select count(*) from member_t where create_date = date_format(now(),'%Y-%m-%d')")
    Integer findMemberByDay();
    //预约统计
    @Select("select count(id) from order_t")
    Integer findOrder();
    @Select("SELECT count(*) FROM order_t where date_format(order_date,'%Y-%m') = date_format(curdate() , '%Y-%m')")
    Integer findOrderByMonth();
    @Select("SELECT count(*) FROM  order_t WHERE YEARWEEK(order_date) = YEARWEEK(now())")
    Integer findOrderByWeek();
    @Select("select count(*) from order_t where order_date = date_format(now(),'%Y-%m-%d')")
    Integer findOrderByDay();
    //预约到诊统计
    @Select("select order_status,setmeal_id from order_t")
    List<Order> findOrderExamine();
    @Select("SELECT count(*) FROM order_t where date_format(order_date,'%Y-%m') = date_format(curdate() , '%Y-%m') and order_status = 2")
    Integer findOrderExamineByMonth();
    @Select("SELECT count(*) FROM  order_t WHERE YEARWEEK(order_date) = YEARWEEK(now()) and order_status = 2")
    Integer findOrderExamineByWeek();
    @Select("select count(*) from order_t  where order_status = 2 and order_date = date_format(now(),'%Y-%m-%d')")
    Integer findOrderExamineByDay();
    //热门套餐
    @Select("select name,id,remark from setmeal_t")
    List<Setmeal> findMeal();
    @Select("select count(id) from order_t where setmeal_id = #{setmealId}")
    Integer findOrderByMealId(@Param("setmealId") Long setmealId);
}
